<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>表单</title>
  <link rel="stylesheet" href="${ctx}/static/admin/layui/css/layui.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/formSelects-v4.css">
  </head>
<script>

</script>
  <body>
  	<div class="layui-card-body">
  	<form class="layui-form layui-form-pane">
	  <input name="modules.id" type="hidden" value="${item.id! }" />
	  <div class="layui-row">
	    <div class="layui-col-xs6">
	      <div class="layui-form-item">
	        <label class="layui-form-label">模块名称<font style="color: red">*</font></label>
	        <div class="layui-input-block">
		      <input type="text" name="modules.name" lay-verify="required" placeholder="请输入模块名称" autocomplete="off" class="layui-input" value="${item.name!}" >
		    </div>
	      </div>
	    </div>
          <div class="layui-col-xs6">
              <div class="layui-form-item">
                  <label class="layui-form-label">图标</label>
                  <div class="layui-input-block">
                      <input type="text" id="iconPicker" name="modules.iconcls" lay-filter="iconPicker" class="layui-input" value="${item.iconcls!}">
                  </div>
              </div>
          </div>
	  </div>
	  <div class="layui-row">
          <div class="layui-col-xs6">
              <div class="layui-form-item">
                  <label class="layui-form-label">链接地址<font style="color: red">*</font></label>
                  <div class="layui-input-block">
                      <select name="pid" xm-select="pid" lay-verify="required"  xm-select-radio xm-select-search  ></select>
                    <!--
                      <select name="pid" id="pid" lay-filter="pid">
                          <%for(item in sysRes){%>
                            <option value="${item.id}">${item.name}</option>
                          <%}%>
                      </select>
                      -->
                  </div>
              </div>
          </div>
	    <div class="layui-col-xs6">
	      <div class="layui-form-item" pane="">
	        <label class="layui-form-label">支持附件<font style="color: red">*</font></label>
	        <div class="layui-input-block">
				<input type="radio" name="modules.if_attach"  value="0" id="radio1" lay-verify="required" title="否" >
				<input type="radio" name="modules.if_attach"  value="1" id="radio2" lay-verify="required" title="是" >
		    </div>
	      </div>
	    </div>
	  </div>
   	  <div class="layui-form-item" style="display: none">
     	<div class="layui-input-block">
       	  <button id="submit-btn" class="layui-btn" lay-submit >立即提交</button>
          <button id="reset-btn" type="reset" class="layui-btn layui-btn-primary">重置</button>
   	    </div>
   	  </div>
	</form>
	</div>
  </body>
</html>
<script src="${ctx}/static/admin/layui/layui.js"></script>
<script src="${ctx}/static/admin/js/common.js"></script>
<script>
    var table, params, $, ai = 0;
    layui.use(['jquery','form','table','formSelects','iconPicker'], function(){
        $ = jQuery = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var iconPicker = layui.iconPicker;
        iconPicker.render({
            elem: '#iconPicker',
            type: 'fontClass',
            search: true,
            click: function (data) {
                console.log(data);
            }
        });
        iconPicker.checkIcon('iconPicker', '${item.iconcls!}');

        if("${item.if_attach}"==0){
            $("#radio1").attr("checked","checked");
            $("#radio2").removeAttr("checked");
            form.render();
        }else{
            $("#radio2").attr("checked","checked");
            $("#radio1").removeAttr("checked");
            form.render();
        }
        form.on('submit', function(data){
            $.post('${ctx}/sys_admin/modules/update', $(data.form).serialize(), function(result) {
                if (result.success) {
                    if (params.name == undefined) {
                        table.reload({});
                    } else {
                        table.reload({
                            where:{
                                name : params.name,
                                status : params.status
                            },
                            page: {
                                curr: params.curr
                            }
                        });
                    }
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    layer.msg(result.msg);
                }
            }, 'json');
            return false;
        });

        formSelects.data('pid', 'server', {
            url: '${ctx}/sys_admin/sys/res/getData',
            keyword: 'name',
            keyVal: 'id',
            success: function(id, url, searchVal, result){
                formSelects.value('pid', ['${pid!}']);
            }
        });
    });
</script>
